package com.lanjiu.lib.business;

import com.lanjiu.lib.utils.GUID;
import com.lanjiu.pro.file.FileContent;
import com.lanjiu.pro.file.Friends;
import com.lanjiu.pro.file.Group;
import com.lanjiu.pro.file.GroupMember;
import com.lanjiu.pro.file.Head;
import com.lanjiu.pro.file.OriginalPictureVideoFriendsTransmission;
import com.lanjiu.pro.file.OriginalPictureVideoGroupTransmission;
import com.lanjiu.pro.file.RegisteredUser;
import com.lanjiu.pro.file.Tourists;

/**
 * @description: Proto传输实体构建器
 * @author: Panwei
 * @date: 2019/11/4 14:31
 */
public class OriginalPictureVideoTransmissionCreator {

    private OriginalPictureVideoTransmissionCreator() {
    }

    public static OriginalPictureVideoGroupTransmission group(boolean isRegisteredGroup,
                                                              boolean isRegisteredGroupMember,
                                                              boolean isRegistered,
                                                              String groupId,
                                                              String groupMemberId,
                                                              String userId,
                                                              boolean isPicture) {
        String userType = "";
        if (!isRegisteredGroup && !isRegisteredGroupMember && !isRegistered)
            userType = TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_GUEST_GROUP_GUEST_MEMBER_GUEST_USER;
        if (!isRegisteredGroup && !isRegisteredGroupMember && isRegistered)
            userType = TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_GUEST_GROUP_GUEST_MEMBER_REGISTERED_USER;
        if (!isRegisteredGroup && isRegisteredGroupMember && !isRegistered)
            userType = TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_GUEST_GROUP_REGISTERED_MEMBER_GUEST_USER;
        if (!isRegisteredGroup && isRegisteredGroupMember && isRegistered)
            userType = TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_GUEST_GROUP_REGISTERED_MEMBER_REGISTERED_USER;
        if (isRegisteredGroup && !isRegisteredGroupMember && !isRegistered)
            userType = TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_REGISTERED_GROUP_GUEST_MEMBER_GUEST_USER;
        if (isRegisteredGroup && !isRegisteredGroupMember && isRegistered)
            userType = TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_REGISTERED_GROUP_GUEST_MEMBER_REGISTERED_USER;
        if (isRegisteredGroup && isRegisteredGroupMember && !isRegistered)
            userType = TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_REGISTERED_GROUP_REGISTERED_MEMBER_GUEST_USER;
        if (isRegisteredGroup && isRegisteredGroupMember && isRegistered)
            userType = TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_REGISTERED_GROUP_REGISTERED_MEMBER_REGISTERED_USER;

        String settingsType = isPicture ? TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_PICTURE : TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_VIDEO;

        if (isRegistered) {
            return OriginalPictureVideoGroupTransmission.newBuilder()
                    .setUserType(userType)
                    .setSettingsType(settingsType)
                    .setGroup(Group.newBuilder().setGroupId(groupId).build())
                    .setGroupMember(GroupMember.newBuilder().setGroupMemberId(groupMemberId).build())
                    .setRegisteredUser(RegisteredUser.newBuilder().setUserId(userId).build())
                    .setHead(Head.newBuilder()
                            .setMsgId(GUID.random())
                            .setFromId(userId)
                            .setToId(groupId)
                            .build())
                    .build();
        } else {
            return OriginalPictureVideoGroupTransmission.newBuilder()
                    .setUserType(userType)
                    .setSettingsType(settingsType)
                    .setGroup(Group.newBuilder().setGroupId(groupId).build())
                    .setGroupMember(GroupMember.newBuilder().setGroupMemberId(groupMemberId).build())
                    .setTourists(Tourists.newBuilder().setTemporaryId(userId).build())
                    .setHead(Head.newBuilder()
                            .setMsgId(GUID.random())
                            .setFromId(userId)
                            .setToId(groupId)
                            .build())
                    .build();
        }
    }

    public static OriginalPictureVideoFriendsTransmission friend(boolean isRegistered,
                                                                 String friendUserId,
                                                                 String userId,
                                                                 boolean isPicture) {
        String settingsType = isPicture ? TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_PICTURE : TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_VIDEO;
        if (isRegistered) {
            return OriginalPictureVideoFriendsTransmission.newBuilder()
                    .setUserType(TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_FRIENDS_REGISTERED_USER)
                    .setSettingsType(settingsType)
                    .setFriends(Friends.newBuilder().setFriendsId(friendUserId).build())
                    .setRegisteredUser(RegisteredUser.newBuilder().setUserId(userId).build())
                    .setHead(Head.newBuilder()
                            .setMsgId(GUID.random())
                            .setFromId(userId)
                            .setToId(friendUserId)
                            .build())
                    .build();
        } else {
            return OriginalPictureVideoFriendsTransmission.newBuilder()
                    .setUserType(TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_FRIENDS_GUEST_USER)
                    .setSettingsType(settingsType)
                    .setFriends(Friends.newBuilder().setFriendsId(friendUserId).build())
                    .setTourists(Tourists.newBuilder().setTemporaryId(userId).build())
                    .setHead(Head.newBuilder()
                            .setMsgId(GUID.random())
                            .setFromId(userId)
                            .setToId(friendUserId)
                            .build())
                    .build();
        }
    }

    public static OriginalPictureVideoFriendsTransmission avatar(boolean isRegistered, String userId){
        if (isRegistered) {
            return OriginalPictureVideoFriendsTransmission.newBuilder()
                    .setUserType(TransmissionConstant.ORIGINAL_AVATAR_TRANSMISSION_FRIENDS_REGISTERED_USER)
                    .setSettingsType(TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_PICTURE)
                    .setFriends(Friends.newBuilder().setFriendsId(userId).build())
                    .setRegisteredUser(RegisteredUser.newBuilder().setUserId(userId).build())
                    .setHead(Head.newBuilder()
                            .setMsgId(GUID.random())
                            .setFromId(userId)
                            .setToId(userId)
                            .build())
                    .build();
        } else {
            return OriginalPictureVideoFriendsTransmission.newBuilder()
                    .setUserType(TransmissionConstant.ORIGINAL_AVATAR_TRANSMISSION_FRIENDS_GUEST_USER)
                    .setSettingsType(TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_PICTURE)
                    .setFriends(Friends.newBuilder().setFriendsId(userId).build())
                    .setTourists(Tourists.newBuilder().setTemporaryId(userId).build())
                    .setHead(Head.newBuilder()
                            .setMsgId(GUID.random())
                            .setFromId(userId)
                            .setToId(userId)
                            .build())
                    .build();
        }
    }

    public static OriginalPictureVideoFriendsTransmission apk(String userId) {
        return OriginalPictureVideoFriendsTransmission.newBuilder()
                .setUserType(TransmissionConstant.ORIGINAL_APK_TRANSMISSION_FRIENDS_USER)
                .setSettingsType(TransmissionConstant.ORIGINAL_PICTURE_VIDEO_TRANSMISSION_VIDEO)
                .setFriends(Friends.newBuilder().setFriendsId(userId).build())
                .setRegisteredUser(RegisteredUser.newBuilder().setUserId(userId).build())
                .setHead(Head.newBuilder()
                        .setMsgId(GUID.random())
                        .setFromId(userId)
                        .setToId(userId)
                        .build())
                .build();
    }

    /**
     * 合并好友proto实体
     *
     * @param friend
     * @param content
     * @return
     */
    public static OriginalPictureVideoFriendsTransmission merge(OriginalPictureVideoFriendsTransmission friend, FileContent content) {
        return OriginalPictureVideoFriendsTransmission.newBuilder(friend).setFileContent(content).build();
    }

    /**
     * 合并群组proto实体
     *
     * @param group
     * @param content
     * @return
     */
    public static OriginalPictureVideoGroupTransmission merge(OriginalPictureVideoGroupTransmission group, FileContent content) {
        return OriginalPictureVideoGroupTransmission.newBuilder(group).setFileContent(content).build();
    }
}
